package com.bulletelc.apollopre.module.map;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;

import com.bulletelc.apollopre.R;
import com.tencent.tencentmap.mapsdk.maps.SupportMapFragment;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;

/**
 * author: lhl
 * date  : 2017/11/07
 * desc  : 地图界面
 * <p>
 * 注意,由于腾讯地图sdk没有提供用于管理地图生命周期的Activity,需要用户自己管理,防止内存泄漏
 */

public class MapActivity extends AppCompatActivity {
    private TencentMap tencentMap;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_activity);

        assignViews();
        setListener();
        initMap();
    }

    /**
     * 初始化控件
     */
    private void assignViews() {

    }

    /**
     * 设置监听
     */
    private void setListener() {

    }

    /**
     * 初始化map
     */
    private void initMap() {
        FragmentManager fm = getSupportFragmentManager();
        SupportMapFragment mapFragment= (SupportMapFragment) fm.findFragmentById(R.id.mapFrag);
        tencentMap=mapFragment.getMap();
        tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL);//普通地图
        tencentMap.setTrafficEnabled(false);//实时路况开关

        //UiSettings类设置
        UiSettings mapSettings=tencentMap.getUiSettings();
        mapSettings.setZoomControlsEnabled(true); //缩放控件的显示与隐藏
        mapSettings.setCompassEnabled(false); //指南针的显示与隐藏
        mapSettings.setMyLocationButtonEnabled(true); //定位控件的显示与隐藏

        //标注坐标
        LatLng latLng = new LatLng(39.906901,116.397972);
        Marker marker = tencentMap.addMarker(new MarkerOptions().position(latLng).title("北京").snippet("DefaultMarker"));
    }


}
